 package com.nq.controller.protol;

 import com.nq.common.ServerResponse;
 import com.nq.service.IUserPositionService;
 import javax.servlet.http.HttpServletRequest;

 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;

 @Controller
 @RequestMapping({"/user/position/"})
 public class UserPositionController {
     private static final Logger log = LoggerFactory.getLogger(UserPositionController.class);

     @Autowired
     IUserPositionService iUserPositionService;

     /**
      * 查询用户持仓列表
      * @param request
      * @param pageNum
      * @param pageSize
      * @param state
      * @param stockCode
      * @param stockSpell
      * @return
      */
     @RequestMapping({"list.do"})
     @ResponseBody
     public ServerResponse list(HttpServletRequest request, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                                @RequestParam(value = "state", required = false) Integer state,
                                @RequestParam(value = "stockCode", required = false) String stockCode,
                                @RequestParam(value = "stockSpell", required = false) String stockSpell) {
         return this.iUserPositionService.findMyPositionByCodeAndSpell(stockCode, stockSpell, state, request, 1, Integer.MAX_VALUE);
     }

     //根据股票代码查询用户最早入仓股票
     @RequestMapping({"findUserPositionByCode.do"})
     @ResponseBody
     public ServerResponse findUserPositionByCode(HttpServletRequest request, @RequestParam(value = "stockCode", required = false) String stockCode) {
         return this.iUserPositionService.findUserPositionByCode(request, stockCode);
     }

     /**
      * 根据 id 获取持有股票数量
      * @param stockCode
      * @return
      */
     @RequestMapping({"getHoldNumById.do"})
     @ResponseBody
     public ServerResponse getHoldNumById(HttpServletRequest request, @RequestParam(value = "stockCode") String stockCode) {
         return this.iUserPositionService.getHoldNumById(request, stockCode);
     }

     /**
      * 根据 userId 获取股票交易记录
      * @param request
      * @return
      */
     @RequestMapping({"listPositionDetail.do"})
     @ResponseBody
     public ServerResponse listPositionDetail(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                              @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                                              HttpServletRequest request) {
         return this.iUserPositionService.listPositionDetail(pageNum, pageSize, request);
     }

 }

